--- layout: documentation title: Malloy Documentation footer: /generated/footers/visualizations/segment_maps.html ---

Segment Maps

malloy can create segment maps. By currently it uses US maps and state names.

Segement maps take as input a series take a table with 4 columns, lat, long, lat, long of the segment.

The model and data styles for the subsequent examples is:

define airports is (explore 'malloy-data.faa.airports'
  primary key code
  airport_count is count(*)
);

define flights is (explore 'malloy-data.faa.flights'
  primary key id2
  origin_code renames origin
  destination_code renames destination
  flight_count is count(*)

  routes_map is (reduce
    origin.latitude
    origin.longitude
    latitude2 is destination.latitude
    longitude2 is destination.longitude
    flight_count
  )

  joins
    origin is airports on origin_code,
    destination is airports on destination_code
);

and data styles are

{
  "routes_map": {
    "renderer": "segment_map"
  }
} 

Run as a simple query.

Depararting from Chicago

explore flights : [dep_time : @2003-02, origin.code : 'ORD'] 
| routes_map
7008009001,000flight_count

Run as a turtle.

explore flights : [dep_time : @2003-02, origin.code : 'ORD'] 
| reduce
  routes_map
routes_map
2004006008001,000flight_count

Run as a trellis.

explore flights : [dep_time : @2003-02, origin.code : 'ORD'] 
| reduce
  carrier
  flight_count
  routes_map
carrier flight_count routes_map
UA 9,443 100200300400flight_count
AA 7,255 100200300400flight_count
MQ 4,975 50100150200flight_count
DH 3,906 50100150flight_count
NW 702 150200250300350flight_count

Run as a trellis repeated filtered

explore flights : [dep_time : @2003-02] 
| reduce : [origin.code : 'ORD'|'SFO'|'JFK']
  carrier
  flight_count
   ord is routes_map : [ origin.code: 'ORD']
   sfo is routes_map : [ origin.code: 'SFO']
   jfk is routes_map : [ origin.code: 'JFK']
carrier flight_count ord sfo jfk
UA 13,584 100200300400flight_count 100200300400flight_count 50100150flight_count
AA 9,271 100200300400flight_count 50100150200flight_count 50100150200flight_count
MQ 5,885 50100150200flight_count 1132flight_count 50100150flight_count
DH 4,332 50100150flight_count NaNflight_count 50100150200flight_count
OO 2,338 NaNflight_count 50100150200250300flight_count NaNflight_count